var app = angular.module('app',[]).controller('userlogin',
		function($scope,$http){
	
		$scope.u = {};
		$scope.checked = false;
		$scope.remember = false;
	$scope.userlogin = function(){
		localStorage.setItem('remember', $scope.remember);
		if($scope.u.name == null || ''){
			$scope.msg = "请输入用户名";
			return;
		}
		if($scope.u.pwd == null || ''){
			$scope.msg1 = "请输入密码";
			return;
		}
		$http.post("./uLogin", $scope.u).success(function(data){
			if(data.status == "ok"){
				window.open("./index");
			}else if(data.status == "1"){
				$scope.msg = "该用户不存在，请注册";
				return;
			}else if(data.status == "2"){
				$scope.msg1 = "密码输入错误，请重新输入!";
				return;
			}
		})
	};
	
		if(localStorage.getItem('remember')=='true'){
		$scope.checked = true;
		var userName = localStorage.getItem('userName');
		var pwd = localStorage.getItem('pwd');
		$scope.u.name = userName;
		$scope.u.pwd = pwd;
		window.open("./uLogin")
		}
	$scope.nameIsNull = function(){
		$scope.msg = "";
	}
	$scope.pwdIsNull = function(){
		$scope.msg1 = "";
	}
	
	$scope.myKeyup = function(e){

		var keycode = window.event?e.keyCode:e.which; 
		        if(keycode==13){
		        	$scope.userlogin();
		        }
		};
	
	
})
